package com.sne.airways.system.service.impl;

import com.sne.airways.basecore.exceptions.AppException;
import com.sne.airways.basecore.service.impl.BaseServiceImpl;
import com.sne.airways.system.dao.OperationLogDAO;
import com.sne.airways.system.dto.TdOperationLogDTO;
import com.sne.airways.system.dto.TdUserDTO;
import com.sne.airways.system.pojo.TdOperationLog;
import com.sne.airways.system.pojo.TdUser;
import com.sne.airways.system.service.OperationLogService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: 卞京帅{bjslogin@gmail.com}
 * Date: 12-11-25
 * Time: 上午11:54
 * To change this template use File | Settings | File Templates.
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class OperationLogServiceImpl extends BaseServiceImpl implements OperationLogService{
    @Autowired
    private OperationLogDAO operationLogDAO;

    public List<TdOperationLogDTO> queryOperationLogList(int start, int limit,String moduleName,String opTypeName) throws AppException {
        List<TdOperationLog> operationLogList = operationLogDAO.queryOperationLogList(start,limit,moduleName,opTypeName);
        List<TdOperationLogDTO> operationLogDTOList = new ArrayList<TdOperationLogDTO>();
        for(TdOperationLog operationLog:operationLogList){
            TdOperationLogDTO dto   = new TdOperationLogDTO();
            String[] ignoreProperties = {"createUser","modifyUser"};
            BeanUtils.copyProperties(operationLog, dto, ignoreProperties);
            //设置创建人
            dto.setCreateUser(operationLog.getCreateUser() ==null?null:operationLog.getCreateUser().getUserName());
            //设置修改人
            dto.setModifyUser(operationLog.getModifyUser() == null ? null : operationLog.getModifyUser().getUserName());
            operationLogDTOList.add(dto);
        }
        return operationLogDTOList;  //To change body of implemented methods use File | Settings | File Templates.
    }
    public Integer queryOperationLogCount(String moduleName,String opTypeName) throws AppException {
        return operationLogDAO.queryOperationLogCount(moduleName,opTypeName);
    }
}
